#include "dexfile-ext.h"
void CDexFileExt::ListMethods()
{
	char *p=(char *)GetMethodIdsAddr();
	for(int i=0;i<GetMethodIdsSize();i++){
		printf("\nMethod [%d]:",i);
		int idx=((CDexMethodidItem*)p)->GetNameIdx();
		char *s=GetTypeIdString(idx);

		if(s){
			printf("%s",s);
		}
		p+=((CDexMethodidItem*)p)->Size();
	}
}
void CDexFileExt::ListProtos()
{
	char *p=(char *)GetProtoIdsAddr();
	for(int i=0;i<GetProtoIdsSize();i++){
		printf("\nProto [%d]:",i);
		int idx=((CDexProtoidItem*)p)->GetShortyIdx();
		char *s=GetTypeIdString(idx);

		if(s){
			printf("%s",s);
		}
		p+=((CDexProtoidItem*)p)->Size();
	}
}

void CDexFileExt::ListFields()
{
	char *p=(char *)GetFieldIdsAddr();
	for(int i=0;i<GetFieldIdsSize();i++){
		printf("\nField [%d]:",i);
		int idx=((CDexFieldidItem*)p)->GetNameIdx();
		char *s=GetTypeIdString(idx);

		if(s){
			printf("%s",s);
		}
		p+=((CDexFieldidItem*)p)->Size();
	}
}





void CDexFileExt::ListClasses()
{
	char *p=(char *)GetClassDefsAddr();
	for(int i=0;i<GetClassDefsSize();i++){
		printf("\nClass [%d]:",i);
		int idx=((CDexClassDefs*)p)->GetClassIdx();
		char *s=GetTypeIdString(idx);

		if(s){
			printf("%s",s);
		}
		p+=((CDexClassDefs*)p)->Size();
	}
}
CDexTypeidItem *CDexFileExt::GetTypeId(int Id){
	CDexTypeidItem *p;

	if (Id<GetTypeIdsSize()){
		p=GetTypeIds()+Id;
	}
	else {
		p=NULL;
	}
	return p;
}
char *CDexFileExt::GetString(int id)
{
	char *p;

	if (id<GetStringIdsSize()){
		int off=GetStringIds()[id].GetStringdataOff();
		p= (char*)((CDexStringdataItem*)(pFileBase+off))->GetData();
	}
	else {
		p=NULL;
	}
	return p;
}
char *CDexFileExt::GetTypeIdString(int idx)
{
	char *s;
	CDexTypeidItem *pTypeId=GetTypeId(idx);
	
	if(pTypeId){
		int idx=pTypeId->GetDescriptorIdx();
		s=GetString(idx);
	}
	else{
		s=NULL;
	}
		return s;
}